function [rslt] = test_url(stockid,year)
  %%
  % 从新浪财经上获取数据
  %

  rslt = struct
  [date,data] = get_history(stockid,year);
  rslt.date = date;
  rslt.data = data;

end

function [date,data] = get_history(stockid,year)
  %%
  % 获取历史交易数据
  %

  % 历史交易
  % http://vip.stock.finance.sina.com.cn/corp/go.php/vMS_MarketHistory/stockid/600839.phtml?year=2017&jidu=1
  url = sprintf('http://vip.stock.finance.sina.com.cn/corp/go.php/vMS_MarketHistory/stockid/%s.phtml?year=%d&jidu=1',stockid,year);

  [sourcefile, status] = urlread(url);
  if ~status%判断数据是否全部读取成功
    error('no data\n')

  end

  %要提取的模式，（）中为要提取的内容
  expr1 = '\s+(\d{4}-\d{2}-\d{2})\s*';
  %match返回整个匹配类型，token返回（）标记的位置，都为元胞类型
  [datefile, date_tokens]= regexp(sourcefile, expr1, 'match', 'tokens');
  amount = size(date_tokens,2);
  date = cell(size(date_tokens));
  data = zeros(amount,6);

  %从源文件中获取目标数据
  expr2 = '<div align="center">(\d*\.?\d*)</div>';
  [datafile, data_tokens] = regexp(sourcefile, expr2, 'match', 'tokens');
  for idx = 1:amount
    date{idx} = date_tokens{idx}{1};
    for col=1:6
      data(idx,col) = str2double(data_tokens{(idx-1)*6+col}{1});
    end
  end
end

